feat(docs): add hreflang alternate links for localized pages#35
Merged
Conversation
Every page is rendered in 19 locales and emits canonical + og:locale, but no hreflang alternates exist, so search engines can't associate the locale variants and they compete as duplicate content. Emit <link rel="alternate" hreflang="..."> for each locale that publishes the same slug, plus an x-default pointing at the English version. Tags are self-referential and gated on a canonical origin; hidden/noindex pages and hidden locale variants are excluded. Adds smoke checks for the en home page (self + x-default) and the it/channels page (cross-link back to English).
Contributor
|
Landed in 6f8c6d6. Tested before merge:
GitHub checks on the PR head were green before merge: Docs Code CI and CodeQL. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The docs site renders every page in 19 locales and already emits
<link rel="canonical">, per-locale<html lang>, andog:locale— but there are nohreflang/rel="alternate"tags anywhere in the output. Without them, search engines can't associate the localized variants of a page, so the translations compete with the English original as duplicate content instead of being served to the right audience by language/region.Change
In
scripts/docs-site/build.mjs, add ahreflangLinks(page)helper that, for each page, emits one<link rel="alternate" hreflang="…">per locale that publishes the same slug, plus anx-defaultpointing at the English version.locales,allPageByKey,pageRoute(), andhtmlLang()(the same building blocks the language picker already uses).noindexpages, and hidden locale variants, are excluded so alternates never point at non-indexable URLs.Verification
npm run docs:build:shell+npm run docs:smoke:shellpass. Sample output for the en home page:Localized pages cross-link back to English, e.g.
it/channelsemitshreflang="en" → /channelsandx-default → /channels. Anoindexpage emits zero alternates.Added
smoke.mjsassertions covering the en home page (self + x-default) and the it/channels page (cross-link back to English).